﻿using Microsoft.Extensions.DependencyInjection;
using Modules.CheckInCount.Entitys;
using Modules.CheckInCount.Repositories;
using PmSoft;

namespace Modules.CheckInCount;

/// <summary>
/// 考勤按月统计服务类
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class CheckInCountService
{
    private readonly CountPerdayRepository countPerdayRepository;
    private readonly CountPermonthRepository countPermonthRepository;

    public CheckInCountService(CountPermonthRepository countPermonthRepository, CountPerdayRepository countPerdayRepository)
    {
        this.countPermonthRepository = countPermonthRepository;
        this.countPerdayRepository = countPerdayRepository;
    }

    /// <summary>
    /// 获取指定条件每日统计
    /// </summary>
    /// <param name="tenantType"></param>
    /// <param name="countType"></param>
    /// <param name="date"></param>
    /// <param name="objectId"></param>
    /// <returns></returns>
    public CountPerday? GetCountPerday(CountTenantType tenantType, CountType countType, DateTime date, int objectId)
    {
        return GetCountPerdays(tenantType, countType, date, new int[] { objectId }).FirstOrDefault();
    }

    /// <summary>
    /// 获取指定条件每日统计集合
    /// </summary>
    /// <param name="tenantType"></param>
    /// <param name="countType"></param>
    /// <param name="date"></param>
    /// <param name="objectIds"></param>
    /// <returns></returns>
    public IEnumerable<CountPerday> GetCountPerdays(CountTenantType tenantType, CountType countType, DateTime date, IEnumerable<int> objectIds)
    {
        return GetCountPerdays(tenantType, countType, date.Year, date.Month, date.Day, objectIds);
    }

    /// <summary>
    /// 获取指定条件每日统计
    /// </summary>
    /// <param name="tenantType"></param>
    /// <param name="countType"></param>
    /// <param name="year"></param>
    /// <param name="month"></param>
    /// <param name="day"></param>
    /// <param name="objectId"></param>
    /// <returns></returns>
    public CountPerday? GetCountPerday(CountTenantType tenantType, CountType countType, int year, int month, int day, int objectId)
    {
        return GetCountPerdays(tenantType, countType, year, month, day, new int[] { objectId }).FirstOrDefault();
    }

    /// <summary>
    /// 获取指定条件每日统计集合
    /// </summary>
    /// <param name="tenantType">计数租户类型</param>
    /// <param name="countType">计数类型</param>
    /// <param name="year">年</param>
    /// <param name="month">月</param>
    /// <param name="day">日</param>
    /// <param name="objectIds">对象集合</param>
    /// <returns></returns>
    public IEnumerable<CountPerday> GetCountPerdays(CountTenantType tenantType, CountType countType, int year, int month, int day, IEnumerable<int> objectIds)
    {
        return countPerdayRepository.GetCountPerdays(tenantType, countType, year, month, day, objectIds);
    }

    /// <summary>
    /// 获取指定条件每月统计
    /// </summary>
    /// <param name="tenantType"></param>
    /// <param name="countType"></param>
    /// <param name="date"></param>
    /// <param name=""></param>
    /// <returns></returns>
    public CountPermonth? GetCountPermonth(CountTenantType tenantType, CountType countType, DateTime date, int objectId)
    {
        return GetCountPermonths(tenantType, countType, date, new int[] { objectId }).FirstOrDefault();
    }

    /// <summary>
    /// 获取指定条件每月统计集合
    /// </summary>
    /// <param name="tenantType"></param>
    /// <param name="countType"></param>
    /// <param name="date"></param>
    /// <param name="objectIds"></param>
    /// <returns></returns>
    public IEnumerable<CountPermonth> GetCountPermonths(CountTenantType tenantType, CountType countType, DateTime date, IEnumerable<int> objectIds)
    {
        return GetCountPermonths(tenantType, countType, date.Year, date.Month, objectIds);
    }

    /// <summary>
    /// 获取指定条件每月统计
    /// </summary>
    /// <param name="tenantType"></param>
    /// <param name="countType"></param>
    /// <param name="year"></param>
    /// <param name="month"></param>
    /// <param name="objectId"></param>
    /// <returns></returns>
    public CountPermonth? GetCountPermonth(CountTenantType tenantType, CountType countType, int year, int month, int objectId)
    {
        return GetCountPermonths(tenantType, countType, year, month, new int[] { objectId }).FirstOrDefault();
    }

    /// <summary>
    /// 获取指定条件每月统计集合
    /// </summary>
    /// <param name="tenantType">计数租户类型</param>
    /// <param name="countType">计数类型</param>
    /// <param name="year">年</param>
    /// <param name="month">月</param>
    /// <param name="objectIds">对象集合</param>
    /// <returns></returns>
    public IEnumerable<CountPermonth> GetCountPermonths(CountTenantType tenantType, CountType countType, int year, int month, IEnumerable<int> objectIds)
    {
        return countPermonthRepository.GetCountPermonths(tenantType, countType, year, month, objectIds);
    }
}